/*
 * Saphre - Suffix Arrays for Phrase Extraction
 * Copyright (C) 2013 
 * Dale Gerdemann - Tübingen, Germany 
 * Niko Schenk - Frankfurt am Main, Germany
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
package util;

import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;

public class Array {

    public static boolean equal(int[] arr1, int[] arr2) {
        if (arr1.length != arr2.length) {
            return false;
        }
        for (int i = 0; i < arr1.length; i++) {
            if (arr1[i] != arr2[i]) {
                return false;
            }
        }
        return true;
    }

    public static int[] subarray(int[] arr, int begin, int end) {
        int[] result = new int[end - begin];
        for (int i = begin; i < end; i++) {
            result[i - begin] = arr[i];
        }
        return result;
    }

    public static int[] plus(int[] arr1, int[] arr2) {
        int[] result = new int[arr1.length + arr2.length];
        int i = 0;
        for (int v : arr1) {
            result[i++] = v;
        }
        for (int v : arr2) {
            result[i++] = v;
        }
        return result;
    }

    public static int[] plus(int[] arr1, int[] arr2, int[] arr3) {
        int[] result = new int[arr1.length + arr2.length + arr3.length];
        int i = 0;
        for (int v : arr1) {
            result[i++] = v;
        }
        for (int v : arr2) {
            result[i++] = v;
        }
        for (int v : arr3) {
            result[i++] = v;
        }
        return result;
    }

    public static int[] plus(int[] arr1, int[] arr2, int[] arr3, int[] arr4) {
        int[] result = new int[arr1.length + arr2.length + arr3.length
                + arr4.length];
        int i = 0;
        for (int v : arr1) {
            result[i++] = v;
        }
        for (int v : arr2) {
            result[i++] = v;
        }
        for (int v : arr3) {
            result[i++] = v;
        }
        for (int v : arr4) {
            result[i++] = v;
        }
        return result;
    }

    public static List<Integer> plusL(int[] arr1) {
        List<Integer> result = new ArrayList<Integer>(arr1.length);
        for (int v : arr1) {
            result.add(v);
        }
        return result;
    }

    public static List<Integer> plusL(int[] arr1, int[] arr2) {
        List<Integer> result = new ArrayList<Integer>(arr1.length + arr2.length);
        for (int v : arr1) {
            result.add(v);
        }
        for (int v : arr2) {
            result.add(v);
        }
        return result;
    }

    public static List<Integer> plusL(int[] arr1, int[] arr2, int[] arr3) {
        List<Integer> result = new ArrayList<Integer>(arr1.length + arr2.length + arr3.length);
        for (int v : arr1) {
            result.add(v);
        }
        for (int v : arr2) {
            result.add(v);
        }
        for (int v : arr3) {
            result.add(v);
        }
        return result;
    }

    public static void main(String[] args) {
        int[] a = {1, 3};
        int[] b = {2, 3, 4};

        System.out.println(Arrays.toString(plus(a, b)));
    }
}
